﻿using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_YBBModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            string eventType = Convert.ToString(this.txtPatientVersion.Text);
            string txtCenter = Convert.ToString(this.Center.Text);
            string stationID = Convert.ToString(this.Station.Text);
            string agentID = Convert.ToString(this.txtAgentWorkID.Text);
            string doctorAndNurse = Convert.ToString(this.txtDoctorAndNurse.Text);
            string txtDiseasesClassification = Convert.ToString(this.txtDiseasesClassification.Text);
            string txtIllnessClassification = Convert.ToString(this.txtIllnessClassification.Text);
            string txtDeathCase = Convert.ToString(this.txtDeathCase.Text);
            string txtMeasures = Convert.ToString(this.txtMeasures.Text);
            string txtFirstAidEffect = Convert.ToString(this.txtFirstAidEffect.Text);
            string txtSex = Convert.ToString(this.txtSex.Text);
            string txtAge = Convert.ToString(this.txtAge.Text);
            string Rosc = Convert.ToString(this.HiddenForRosc.Value);
            string start1 = beginTime.ToString();
            string end1 = endTime.ToString();

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            TJDAL dal = new TJDAL();
            switch (reportName)
            {            
                case "TJ_BZFL.rdlc":
                    this.Page.Title = "病种分类统计表";
                    DataTable dt1 = dal.Get_TJ_BZFL(beginTime, endTime, eventType, stationID, agentID, doctorAndNurse,
                  txtCenter, txtDiseasesClassification, txtIllnessClassification, txtDeathCase, txtMeasures, txtFirstAidEffect,
                  txtSex, txtAge);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_BZFL", dt1));
                    break;
                case "TJ_BZFLXL.rdlc":
                    this.Page.Title = "病种分类(细化)统计表";
                    DataTable dt20 = dal.Get_TJ_BZFLXL(beginTime, endTime, eventType, stationID, agentID, doctorAndNurse,
                   txtCenter, txtDiseasesClassification, txtIllnessClassification, txtDeathCase, txtMeasures, txtFirstAidEffect,
                   txtSex, txtAge);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_BZFLXL", dt20));
                    break;
                case "TJ_YBB.rdlc":
                    this.Page.Title = "院前急救病种和疗效情况统计月报表";
                    DataTable dt2 = dal.Get_TJ_YBB(beginTime, endTime, eventType, stationID, agentID, doctorAndNurse,
                  txtCenter, txtDiseasesClassification, txtIllnessClassification, txtDeathCase, txtMeasures, txtFirstAidEffect,
                  txtSex, txtAge);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_YBB", dt2));
                    break;
                default:
                    break;
            }
            this.ReportViewer1.LocalReport.Refresh();
        }
       
    }
}